<template>
<view>
<image class="fxbacktp" src="/static/remao_shop/img/fxbacktp.png"></image>
<view class="top">
   <image :src="getList.avatar"></image>
   <view class="name">{{getList.username}}</view>
   <view class="name">{{rank_name}}</view>
   <view class="top-mes">
      推荐人：<text class="name">{{getList.parent_name}}</text>
      邀请码：<text class="aa">{{uid}}</text>
      <!-- 等级：<text>{{getList.class}}</text> -->
   </view>
   <!-- <view class='top-code'>
      邀请码：<text class='aa'>{{uid}}</text>
      手机号：<text>{{getList.phone}}</text>
   </view> -->
</view>
<view class="money">
   <view class="money-a">
      <text>我的佣金</text>
      <view>￥{{getList.my_commission}}</view>
   </view>
   <view class="money-a">
      <text>可提现佣金</text>
      <view>￥{{getList.withdraw}}</view>
      <button @click="deposit">提现</button>
   </view>
   <view class="money-a">
      <text>成功提现佣金</text>
      <view>￥{{getList.have_withdrawal}}</view>
   </view>
</view>
<view class="contents">
   <view>
      <navigator url="../../packageB/DistributionCommission/DistributionCommission">
         <image src="/static/remao_shop/img/distributiona.png"></image>
         <view>分销佣金</view>
      </navigator>
   </view>
   <view>
      <navigator url="../../packageB/DetailedCommission/DetailedCommission">
         <image src="/static/remao_shop/img/detail.png"></image>
         <view>佣金明细</view>
      </navigator>
   </view>
   <view>
      <navigator url="../../packageB/DetailsOfWithdrawal/DetailsOfWithdrawal">
         <image src="/static/remao_shop/img/deposit.png"></image>
         <view>提现明细</view>
      </navigator>
   </view>
   <view>
      <navigator url="../../packageB/inserting/inserting">
         <image src="/static/remao_shop/img/descendent.png"></image>
         <view>我的下线</view>
      </navigator>
   </view>
   <!-- <view>
      <navigator url='../../packageB/QRCode/QRCode'>
         <image src='../../img/code.png'></image>
         <view>推广二维码</view>
      </navigator>
   </view> -->
   <view>
      <navigator url="../../packageB/Rich/Rich">
         <image src="/static/remao_shop/img/announcement.png"></image>
         <view>富豪榜</view>
      </navigator>
   </view>
</view>
</view>
</template>

<script>
// hotmall/packageB/DistributionCenter/DistributionCenter.js
var app = getApp();
import api from "../../../api";
var iswe7 = wx.getStorageSync("iswe7");

export default {
  data() {
    return {
      uid: '',
      getList: [],
      rank_name: '',
      xiaoKong: ""
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options) {
      this.setData({
        xiaoKong: options.kong
      });
    }

    wx.getStorage({
      key: 'userId',
      success: res => {
        this.setData({
          uid: res.data
        });
        console.log(this.uid);
        this.getListFun();
        this.getRank_name();
      },
      fail: res => {
        if (this.xiaoKong != 1) {
          console.log(res);
          wx.showToast({
            title: '请先登录'
          });

          if (iswe7 == 1) {
            wx.navigateTo({
              url: '../../packageA/login/login'
            });
          } else {
            wx.navigateTo({
              url: '../../packageA/logins/login'
            });
          }

          this.setData({
            xiaoKong: 1
          });
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //   this.getList();
    if (this.xiaoKong == 1) {
      this.onLoad();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getListFun();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    getListFun: function () {
      app.globalData.request({
        url: api.default.distribution_index_sales,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          uid: this.uid
        },
        method: 'POST',
        success: res => {
          console.log(res);
          var list = res.msg;
          list.my_commission = Number(list.my_commission).toFixed(2);
          list.withdraw = Number(list.withdraw).toFixed(2);
          list.have_withdrawal = Number(list.have_withdrawal).toFixed(2);
          this.setData({
            getList: list
          });
        }
      });
    },

    getRank_name() {
      app.globalData.request({
        url: 'http://hotmall.shiliucrm.com/api/user/user_info',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          uid: this.uid
        },
        method: 'POST',
        success: res => {
          console.log(res);
          this.setData({
            rank_name: res.user_info.rank_name
          });
        }
      });
    },

    deposit() {
      wx.navigateTo({
        url: '../Cash/Cash?withdraw=' + this.getList.withdraw
      });
    }

  }
};
</script>
<style>
@import "./DistributionCenter.css";
</style>